import {defineStore} from 'pinia';
import {CacheManager} from "/@/cache";
import {userApi} from "/@/api/user";

/**
 * 用户信息
 * @methods setUserInfos 设置用户信息
 */
export const useUserInfo = defineStore('userInfo', {
    state: (): UserInfoState => ({
        userInfo: CacheManager.getUserInfo() || {
            id: 0,
            avatar: "",
            permissions: [],
            roles: [],
            username: "",
            createTime: undefined,
            createUser: 0,
            email: "",
            gender: "",
            mobile: "",
            nickname: "",
            realName: "",
            resume: "",
            updateTime: undefined,
            updateUser: 0
        }
    }),
    actions: {
        //刷新用户信息
        async refreshUserInfo() {
            const data: AdminUserVo = await userApi.info();
            data.avatar = "https://img2.baidu.com/it/u=1978192862,2048448374&fm=253&fmt=auto&app=138&f=JPEG?w=504&h=500";
            // data.avatar = "https://img2.baidu.com/it/u=2370931438,70387529&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500";
            CacheManager.setUserInfo(data);
            this.userInfo = data;
        },
    },
});
